/*
 * @lc app=leetcode.cn id=1380 lang=javascript
 *
 * [1380] 矩阵中的幸运数
 */

// @lc code=start
/**
 * @param {number[][]} matrix
 * @return {number[]}
 */
var luckyNumbers = function (matrix) {
  let row = [], col = [];
  for (let i = 0; i < matrix.length; i++) {
    for (let j = 0; j < matrix[i].length; j++) {
      if (row[i] === undefined) {
        row[i] = matrix[i][j];
      } else {
        row[i] = Math.min(row[i], matrix[i][j])
      }
      if (col[j] === undefined) {
        col[j] = matrix[i][j];
      } else {
        col[j] = Math.max(col[j], matrix[i][j])
      }
    }
  }
  return row.filter(item => col.includes(item));
};
// @lc code=end
